{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "# Querying the Graph data\n",
    "\n",
    "Once the data has been loaded into the database, we can run some gremlin queries to query the data in the graph database.\n",
    "\n",
    "Below we have examples of a few Gremlin queries to get the count of vertices and edges in the graph as well as to get the counts by vertex label and edge label."
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cd27cae0-9aad-47cc-a1fa-46ea561d4e1e",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "%%gremlin\n",
    "g.V().count().next()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7f434bc3-ddca-4979-a580-f1f416a1443a",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "%%gremlin\n",
    "g.E().count().next()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8f22769f-1f97-4e03-b3a3-aa62e44f4b42",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "%%gremlin\n",
    "g.V().groupCount().by(label).unfold().order().by(keys)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ae383337-74bb-4105-8c4a-6acf93edde42",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "%%gremlin\n",
    "g.E().groupCount().by(label).unfold().order().by(keys)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4240519a-2dba-401c-81f2-4860848672f0",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "%%gremlin\n",
    "g.V().values('user_attr_1').mean().next()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "13b6adf4-5d33-4957-8e32-db897a0d4a6e",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "%%gremlin\n",
    "g.V().values('user_attr_1').min().next()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ededeb32-e1f5-4b29-bf03-e7dc557ad960",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# Find the distinct values of a property in vertices\n",
    "distinct_values = g.V().values('user_attr_1').dedup().toList()\n",
    "#print(\"Distinct values:\", distinct_values)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "76a5b6da-e855-49d2-b120-374dd7a8ea2e",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "%%gremlin\n",
    "g.V().hasLabel('user').properties().count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f99bb270-0d9c-4b44-bef2-332306bab4fb",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "%%gremlin\n",
    "g.V().hasLabel('user').properties().key().dedup().count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c1fd63ad-f0ad-4f38-9e5c-4832d2d7fc51",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "%%gremlin\n",
    "g.V().hasLabel('cell').properties().key().dedup().count() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4b96732c-f6fa-4c60-a0a9-a15610885b6b",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "%%gremlin\n",
    "g.V().hasLabel('cell').properties().count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f23d18bb-1ee8-4374-8197-1d0b8dc1e62b",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "%%gremlin\n",
    "g.E().hasLabel('user_live_cell').properties().key().dedup().count() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "13594594-0ff0-42d5-a5b2-205c8a39860c",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "%%gremlin\n",
    "g.E().hasLabel('user_live_cell').properties().count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8a705292-849d-4a55-98ca-f75dd7b3892b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}